import matplotlib.pyplot as plt
from skimage.data import camera
from skimage.filters import sobel,sobel_v,sobel_h
from skimage import io,color
"""
中文显示工具函数
"""
def set_ch():
    from pylab import mpl
    mpl.rcParams['font.sans-serif']=['FangSong']
    mpl.rcParams['axes.unicode_minus']=False
set_ch()

# image = camera()
image = io.imread('lena.bmp') 
image=color.rgb2gray(image)
edge_sobel = sobel(image)
edge_sobel_v=sobel_v(image)
edge_sobel_h=sobel_h(image)

fig, ax = plt.subplots(ncols=2, nrows=2,sharex=True, sharey=True,
                    figsize=(8, 4))
ax[0,0].imshow(image, cmap=plt.cm.gray)
ax[0,0].set_title('原始图像')

ax[0,1].imshow(edge_sobel, cmap=plt.cm.gray)
ax[0,1].set_title('Sobel 边缘检测')


ax[1,0].imshow(edge_sobel_v, cmap=plt.cm.gray)
ax[1,0].set_title('Sobel 垂直边缘检测')

ax[1,1].imshow(edge_sobel_h, cmap=plt.cm.gray)
ax[1,1].set_title('Sobel 水平边缘检测')

for a in ax:
    for j in a:
        j.axis('off')

plt.tight_layout()
plt.show()
